﻿namespace Szabalyrendszer
{
    public class Tulajdonsag
    {
        #region Constructors
        
        public Tulajdonsag() { }

        public Tulajdonsag(int ertek)
        {
            Ertek = ertek;
        } 

        #endregion

        #region Comparison

        protected bool Equals(Tulajdonsag other)
        {
            return Ertek == other.Ertek;
        }

        public override bool Equals(object obj)
        {
            if (obj is int)
            {
                return Ertek == (int) obj;
            }
            var tulajdonsag = obj as Tulajdonsag;
            if (tulajdonsag != null)
            {
                return Ertek == tulajdonsag.Ertek;
            }
            return false;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public static bool operator ==(int t1, Tulajdonsag t2)
        {
            return t2 != null && t1 == t2.Ertek;
        }

        public static bool operator !=(int t1, Tulajdonsag t2)
        {
            return !(t1 == t2);
        }

        public static bool operator ==(Tulajdonsag t1, Tulajdonsag t2)
        {
            return t1 != null && (t2 != null && t1.Ertek == t2.Ertek);
        }

        public static bool operator !=(Tulajdonsag t1, Tulajdonsag t2)
        {
            return !(t1 == t2);
        }

        public static bool operator ==(Tulajdonsag t1, int t2)
        {
            return t1 != null && t1.Ertek == t2;
        }

        public static bool operator !=(Tulajdonsag t1, int t2)
        {
            return !(t1 == t2);
        }

        #endregion
        
        public int Ertek { get; set; }

        #region Proba

        public bool Proba(int modosito)
        {
            return Proba(Kockadobo.Instancia.Dob(1, 10, 0), modosito);
        }

        public bool Proba()
        {
            return Proba(Kockadobo.Instancia.Dob(1, 10, 0));
        }

        public bool Proba(int dobas, int modosito)
        {
            return dobas + modosito <= Ertek;
        }

        #endregion

        #region Multiplication

        public static int operator +(Tulajdonsag t1, Tulajdonsag t2)
        {
            return t1.Ertek + t2.Ertek;
        }

        public static int operator +(Tulajdonsag t1, int t2)
        {
            return t1.Ertek + t2;
        }

        public static int operator +(int t1, Tulajdonsag t2)
        {
            return t1 + t2.Ertek;
        }

        #endregion

        #region Impolicit cast

        public static implicit operator int(Tulajdonsag tulajdonsag)
        {
            return tulajdonsag.Ertek;
        }

        public static implicit operator Tulajdonsag(int ertek)
        {
            return new Tulajdonsag {Ertek = ertek};
        }

        #endregion
    }
}
